package com.atguigu.edu.realtime.common.function;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.PropertyNamingStrategy;
import com.alibaba.fastjson.serializer.SerializeConfig;
import org.apache.flink.api.common.functions.MapFunction;

public class BeanToJsonStrMapFunction<T> implements MapFunction<T,String> {
    @Override
    public String map(T t) throws Exception {
        SerializeConfig config = new SerializeConfig();
        //设置命名策略，对象转换成json，json最后是往数据库写，往数据库写就需要字符串
        config.setPropertyNamingStrategy(PropertyNamingStrategy.SnakeCase);
        return JSON.toJSONString(t, config);
    }
}
